package cultu.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cultu.community.message.Community;
import cultu.supplier.message.Product;

/**
 * Cultu utils class.
 * @author Marc-Antoine
 *
 */
public class CultuUtils
{

  /**
   * Check if community is a universe.
   *
   * @param community the community to check.
   * @return true, if successful
   */
  public static boolean communityIsUniverse(final Community community) {
    if (community == null)
    {
      return false;
    }
    
    return !nullOrEmpty(community.getUniverse()) && nullOrEmpty(community.getCategory()) && nullOrEmpty(community.getFamily()) && nullOrEmpty(community.getKind());
  }
  
  /**
   * Check if community is a category.
   *
   * @param community the community to check.
   * @return true, if successful
   */
  public static boolean communityIsCategory(final Community community) {
    if (community == null)
    {
      return false;
    }
    
    return !nullOrEmpty(community.getUniverse()) && !nullOrEmpty(community.getCategory()) && nullOrEmpty(community.getFamily()) && nullOrEmpty(community.getKind());
  }
  
  /**
   * Check if community is a family.
   *
   * @param community the community to check.
   * @return true, if successful
   */
  public static boolean communityIsFamily(final Community community) {
    if (community == null)
    {
      return false;
    }
    
    return !nullOrEmpty(community.getUniverse()) && !nullOrEmpty(community.getCategory()) && !nullOrEmpty(community.getFamily()) && nullOrEmpty(community.getKind());
  }
  
  /**
   * Check if community is a kind.
   *
   * @param community the community to check.
   * @return true, if successful
   */
  public static boolean communityIsKind(final Community community) {
    if (community == null)
    {
      return false;
    }
    
    return !nullOrEmpty(community.getUniverse()) && !nullOrEmpty(community.getCategory()) && !nullOrEmpty(community.getFamily()) && !nullOrEmpty(community.getKind());
  }
  
  /**
   * Check if string is null or empty.
   *
   * @param string the string to check.
   * @return true, if successful
   */
  public static boolean nullOrEmpty(final String string) {
    return string == null || "".equals(string);
  }
  
  /**
   * Return true if the community is in list.
   *
   * @param communitiesList the list to fetch.
   * @param communityToSearch the entity to search.
   * @return true, if successful
   */
  public static boolean contains(final List<Community> communitiesList, final Community communityToSearch) {
    if (communitiesList == null || communityToSearch == null)
    {
      return false;
    }
    
    // Looking after element.
    for (Community community : communitiesList) {
      if (community.getHjid().equals(communityToSearch.getHjid()))
      {
        return true;
      }
    }
    
    return false;
  }
  
  /**
   * Return true if the product is in list.
   *
   * @param productList the list to fetch.
   * @param productToSearch the entity to search.
   * @return true, if successful
   */
  public static boolean contains(final List<Product> productList, final Product productToSearch) {
    if (productList == null || productToSearch == null)
    {
      return false;
    }
    
    // Looking after element.
    for (Product product : productList) {
      if (product.getHjid().equals(productToSearch.getHjid()))
      {
        return true;
      }
    }
    
    return false;
  }
  
  /**
   * Communities css classes.
   *
   * @return CSS - community map.
   */
  public static Map<String, String> communitiesCSSClasses() {
    
    // The hash map.
    final Map<String, String> communitiesCSSMap = new HashMap<String, String>();
    
    communitiesCSSMap.put("recommandations", "product-album with-summary-right");
    communitiesCSSMap.put("livres", "product-poster");
    communitiesCSSMap.put("applications", "product-application");
    communitiesCSSMap.put("musiques", "product-album");
    communitiesCSSMap.put("films", "product-poster");
    
    return communitiesCSSMap;
  }
}
